<?php
/**
给定一个排序链表，删除所有重复的元素，使得每个元素只出现一次。

示例 1:

输入: 1->1->2
输出: 1->2
示例 2:

输入: 1->1->2->3->3
输出: 1->2->3
 */

class ListNode {
    public $val = 0;
    public $next = null;
    function __construct($val)
    {
        $this->val = $val;
    }
}

class Solution {

    /**
     * @param ListNode $head
     * @return ListNode
     */
    function deleteDuplicates($head) {
        if ($head == null || $head->next == null) {
            return $head;
        }
        $curr = $head;
        while ($curr != null && $curr->next != null) {
            if ($curr->val == $curr->next->val) {
                $curr->next = $curr->next->next;
            } else {
                $curr = $curr->next;
            }
        }
        return $head;
    }
}